var ClubMemberWindow = Window.extend({
    _ccsFileName: res.ClubMemberWindow_json,
    _clubId: null,
    _membersViewList: [],
    _originalList: [],
    _onlineMemberNum: 0,
    initWindow: function (clubId) {
        this._clubId = clubId;
        this._initTableView();
        clubMsgManager.requestClubMember(this._clubId);
    },

    /**
     * 初始化TableView
     * @private
     */
    _initTableView: function () {
        var nodeContent = this._nodeList['nodeContent'];
        var tableViewSize = nodeContent.getContentSize();
        this._tableView = new cc.TableView(this, cc.size(tableViewSize.width, tableViewSize.height));
        this._tableView.setDelegate(this);
        this._tableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
        this._tableView.setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN);
        nodeContent.addChild(this._tableView);
    },

    _initClickListeners: function () {
        this._clickListeners = {
            'btn_find': '_clickFind',
        }
    },
    /**
     * 监听亲友圈消息
     * @private
     */
    _initEventListeners: function () {
        this._eventListeners = {};
        this._eventListeners[ClubMsgCode.AllMemberInfo] = '_allMemberInfoHandler';
    },

    _clickFind: function () {
        var inputNode = this._nodeList['input'];
        inputNode.didNotSelectSelf();
        var input = inputNode.getString();
        var viewList = [];
        if (!input) {
            showAlert('请输入玩家ID或名称');
            viewList = this._originalList;
        } else {
            var findUser = [];
            for (var i = 0; i < this._originalList.length; i++) {
                var data = this._originalList[i];
                if (data['name'].indexOf(input) >= 0 || data['uid'].toString().indexOf(input) >= 0) {
                    findUser.push(data);
                }
            }
            viewList = findUser;
        }
        if (viewList.length > 0) {
            this._membersViewList = viewList;
            this._tableView.reloadData();
        }
    },

    _allMemberInfoHandler: function () {
        var memberObj = ClubDataManager.getClubMembersSort(this._clubId);
        this._originalList = memberObj.member;
        this._onlineMemberNum = memberObj.onlineMemberNum;
        this._nodeList['player_num'].setString('在线人数:' + this._onlineMemberNum + '/' + this._originalList.length);
        this._membersViewList = this._originalList;
        this._tableView.reloadData();
    },

    tableCellAtIndex: function (table, idx) {
        var cell = table.dequeueCell();
        var node = null;
        if (cell == null) {
            cell = new cc.TableViewCell();
            node = addItem('ClubMemberItem2', cell, (idx + 1), this._membersViewList[idx]);
            node.setName("itemCell");
        } else {
            node = cell.getChildByName("itemCell");
            node.setData((idx + 1), this._membersViewList[idx]);
        }
        return cell;
    },
    tableCellTouched: function (table, cell) {
    },
    tableCellSizeForIndex: function (table, idx) {
        return cc.size(1163, 86);
    },
    numberOfCellsInTableView: function (table) {
        return this._membersViewList.length;
    },

});